/**
 * 
 */
package ultility.validate;

/**
 * @author NhatHung
 *
 */
public class Validate {
	final public static String NUMBER_PATTERN = "\\d";
	final public static String WORD_PATTERN = "\\w";
	final public static String EMAIL_PATTERN = "^[A-Z0-9._%+-]+@[A-Z0-9.-]+\\.[A-Z]{2,6}$";

	// check length of string less than length
	public static boolean validLength(String str, int length) {
		if (length >= str.length()) {
			return true;
		} else {
			return false;
		}
	}

	// check length of string between lengthMin and lengthMax
	public static boolean validLength(String str, int lengthMin, int lengthMax) {
		int length = str.length();
		if (lengthMax >= length & lengthMin <= length) {
			return true;
		} else {
			return false;
		}
	}

	// check regex of string a-zA-Z_0-9
	public static boolean validWord(String str) {
		return str.matches(WORD_PATTERN);
	}

	// check regex of string 0-9
	public static boolean validNumber(String str) {
		return str.matches(NUMBER_PATTERN);
	}

	// check regex of email
	public static boolean validEmail(String str) {
		return str.matches(EMAIL_PATTERN);
	}
}
